package cn.fintecher.gis.utils;

import java.util.List;

/**
 * Created by ChenChang on 2018/1/6.
 */
public class SubListUtil {
    public static <T> void dealForSubList(List<T> totalList, Integer subSize, SubListFunction<T> subListFunction) {

        int count = totalList.size();
        int iteratorCount = count / subSize;
        for (int i = 0; i <= iteratorCount; i++) {
            int endIndex, startIndex;
            startIndex = i * subSize;
            endIndex = ((endIndex = (i + 1) * subSize) > count) ? count : endIndex;
            if (endIndex == startIndex) {
                break;
            }

            List<T> subList = totalList.subList(startIndex, endIndex);

            subListFunction.processor(subList);
        }
    }

    //Function<? super F, ? extends T>
    public interface SubListFunction<T> {

        void processor(List<T> tList);


    }

}
